const Sequelize = require('sequelize');

var config = {
    database: 'jobfree2017',
    username: 'root',
    password: '123456',
    host: 'localhost',
    port: 3306
};

var connection = function () {
    var sequelize = new Sequelize(config.database, config.username, config.password, {
        host: config.host,
        dialect: 'mysql',
        pool: {
            max: 5,
            min: 0,
            idle: 30000
        }
    });
    sequelize.authenticate()
        .then(() => {
            console.log('Connection has been established successfully.');
        })
        .catch((err) => {
            console.error('Unable to connect to the database:', err);
        });
    return sequelize;
};

module.exports = {
    config: config,
    connection: connection
};